class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        n = len(s)
        if n == 0 or n == 1:
            return n
        res = 1
        left = 0
        right = 0
        hash = {}
        for right in range(n):
            if s[right] in hash and hash[s[right]] >= left:
                left = hash[s[right]] + 1
            hash[s[right]] = right
            res = max(res, right - left + 1)

        return res
              
